load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

# gazelle:exclude gen-crdb_test_off.go
# gazelle:exclude gen-crdb_test_on.go

# keep
go_library(
    name = "buildutil",
    srcs = select({
        "//build/toolchains:crdb_test": [":gen-crdb-test-on"],
        "//conditions:default": [":gen-crdb-test-off"],
    }),
    importpath = "github.com/cockroachdb/cockroach/pkg/util/buildutil",
    visibility = ["//visibility:public"],
)

REMOVE_GO_BUILD_CONSTRAINTS = "cat $< | grep -v '//go:build' | grep -v '// +build' > $@"

genrule(
    name = "gen-crdb-test-on",
    srcs = ["crdb_test_on.go"],
    outs = ["gen-crdb_test_on.go"],
    cmd = REMOVE_GO_BUILD_CONSTRAINTS,
)

genrule(
    name = "gen-crdb-test-off",
    srcs = ["crdb_test_off.go"],
    outs = ["gen-crdb_test_off.go"],
    cmd = REMOVE_GO_BUILD_CONSTRAINTS,
)

go_test(
    name = "buildutil_test",
    srcs = ["crdb_test_test.go"],
    embed = [":buildutil"],  # keep
    deps = [
        "//pkg/build/bazel",
        "@com_github_stretchr_testify//require",
    ],
)
